package com.ruoyi.system.service.impl;

import java.sql.ResultSet;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysLooperMapper;
import com.ruoyi.system.domain.SysLooper;
import com.ruoyi.system.service.ISysLooperService;

/**
 * looperService业务层处理
 *
 * @author king
 * @date 2022-07-14
 */
@Service
public class SysLooperServiceImpl extends ServiceImpl<SysLooperMapper,SysLooper> implements ISysLooperService
{
    @Autowired
    private SysLooperMapper sysLooperMapper;
    @Autowired
    private RedisCache redisCache;

    /**
     * 查询looper
     *
     * @param id looper主键
     * @return looper
     */
    @Override
    public SysLooper selectSysLooperById(Long id)
    {
        return sysLooperMapper.selectSysLooperById(id);
    }

    /**
     * 查询looper列表
     *
     * @param sysLooper looper
     * @return looper
     */
    @Override
    public List<SysLooper> selectSysLooperList(SysLooper sysLooper)
    {
        return sysLooperMapper.selectSysLooperList(sysLooper);
    }

    /**
     * 新增looper
     *
     * @param sysLooper looper
     * @return 结果
     */
    @Override
    public int insertSysLooper(SysLooper sysLooper)
    {
        sysLooper.setCreateTime(DateUtils.getNowDate());
        List<SysLooper> cacheList = redisCache.getCacheList(CacheConstants.SYS_LOOPER_KEY);
        if (!cacheList.isEmpty()) {
            redisCache.deleteObject(CacheConstants.SYS_LOOPER_KEY);
        }
        return sysLooperMapper.insertSysLooper(sysLooper);
    }

    /**
     * 修改looper
     *
     * @param sysLooper looper
     * @return 结果
     */
    @Override
    public int updateSysLooper(SysLooper sysLooper)
    {
        sysLooper.setUpdateTime(DateUtils.getNowDate());
        List<SysLooper> cacheList = redisCache.getCacheList(CacheConstants.SYS_LOOPER_KEY);
        if (!cacheList.isEmpty()) {
            redisCache.deleteObject(CacheConstants.SYS_LOOPER_KEY);
        }
        return sysLooperMapper.updateSysLooper(sysLooper);
    }

    /**
     * 批量删除looper
     *
     * @param ids 需要删除的looper主键
     * @return 结果
     */
    @Override
    public int deleteSysLooperByIds(Long[] ids)
    {
        List<SysLooper> cacheList = redisCache.getCacheList(CacheConstants.SYS_LOOPER_KEY);
        if (!cacheList.isEmpty()) {
            redisCache.deleteObject(CacheConstants.SYS_LOOPER_KEY);
        }
        return sysLooperMapper.deleteSysLooperByIds(ids);
    }

    /**
     * 删除looper信息
     *
     * @param id looper主键
     * @return 结果
     */
    @Override
    public int deleteSysLooperById(Long id)
    {
        List<SysLooper> cacheList = redisCache.getCacheList(CacheConstants.SYS_LOOPER_KEY);
        if (!cacheList.isEmpty()) {
            redisCache.deleteObject(CacheConstants.SYS_LOOPER_KEY);
        }
        return sysLooperMapper.deleteSysLooperById(id);
    }
}
